//我发布的书
const {Commodity} = require('../../../models/commodity');

module.exports = async (req, res) => {
    var userId = req.query.user_id;

    let opt = [
        {$match:{"user_id":userId}},
        {
            $lookup:{
                from: "books",
                localField: "ISBN",
                foreignField: "ISBN",
                as: "books"
            },
        },
        {$unwind:"$books"},
        {
            $project:{
                "_id":0,
                "artNo":"$Art_No",
                "img":"$books.img",
                "customPrice":1,
                "ISBN":"$books.ISBN",
                "title":"$books.title",
                "author":"$books.author",
                "publisher":"$books.publisher",
                "price":"$books.price",
                "firstCategory":"$books.firstCategory",
                "secondCategory":"$books.secondCategory",
                "freight":"$freight",
                "appearance":"$appearance",
                "deliveryLocation":"$deliveryLocation",
            }
        },
    ]
    Commodity.aggregate(opt,(err,data)=>{
        if(err){
            console.log(err)
            res.status(500).send({errCode:'1',msg:"服务器错误"})
        }else{
            res.send({errCode:"0",msg:"请求成功",data:{mypublish:data}})
        }
    })
}